package com.gegewa.topic.jdata.sameagain;

import java.text.SimpleDateFormat;
import java.util.*;

public class Client {

    public static void main(String[] args) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowData = simpleDateFormat.format(new Date());
        System.out.println("开始时间：" + nowData);

        forecastUser();

        nowData = simpleDateFormat.format(new Date());
        System.out.println("完成时间：" + nowData);

    }

    private static void forecastPurchaseHandler() {
        DataLoader dataLoader = new DataLoader();
        Map<String, Set<String>> historyMap = dataLoader.loadData();
        ForecastPurchaseHandler forecastPurchaseHandler = new ForecastPurchaseHandler(historyMap);
        List<String[]> forecastList = forecastPurchaseHandler.getForecastPurchaseResult();
        System.out.println("预测购物信息量=" + forecastList.size());

        dataLoader.write(forecastList);
    }

    private static void forecastUser() {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String nowData = "";

        DataLoader dataLoader = new DataLoader();
        Map<String, Integer> userIdHistoryMap = new HashMap<>();
        Map<String, Integer> skuIdHistoryMap = new HashMap<>();

        nowData = simpleDateFormat.format(new Date());
        System.out.println("加载商品开始时间：" + nowData);

        Set<String> productSet = dataLoader.getProductSet();

        nowData = simpleDateFormat.format(new Date());
        System.out.println("加载商品结束时间：" + nowData + "，商品数量：" + productSet.size());

        nowData = simpleDateFormat.format(new Date());
        System.out.println("加载用户购物记录开始时间：" + nowData);

        dataLoader.loadUserIdSkuIdWeight(productSet, userIdHistoryMap, skuIdHistoryMap);

        nowData = simpleDateFormat.format(new Date());
        System.out.println("加载用户购物记录结束时间：" + nowData + "，用户数量：" + userIdHistoryMap.size() + "，商品数量：" + skuIdHistoryMap.size());

        nowData = simpleDateFormat.format(new Date());
        System.out.println("预测购物用户列表开始时间：" + nowData);

        ForecastUser forecastUser = new ForecastUser();
        List<String> userIdList = forecastUser.getUserIdList(userIdHistoryMap);

        nowData = simpleDateFormat.format(new Date());
        System.out.println("预测购物用户列表结束时间：" + nowData + "，预测用户数量：" + userIdList.size());

        nowData = simpleDateFormat.format(new Date());
        System.out.println("预测购物商品开始时间：" + nowData);

        String skuId = forecastUser.getSkuId(skuIdHistoryMap);

        nowData = simpleDateFormat.format(new Date());
        System.out.println("预测购物商品结束时间：" + nowData);

        nowData = simpleDateFormat.format(new Date());
        System.out.println("写入文件开始时间：" + nowData);

        dataLoader.write(userIdList, skuId);

        nowData = simpleDateFormat.format(new Date());
        System.out.println("写入文件结束时间：" + nowData);
    }

    private static void forecastFirstAndSecond() {

        DataLoader dataLoader = new DataLoader();
        Map<String, String> userIdSkuIdMap = new HashMap<>();
        List<String> userIdList = new ArrayList<>();
        dataLoader.readFirstAndSecond(userIdSkuIdMap, userIdList);

        FirstPlusSecond firstPlusSecond = new FirstPlusSecond();
        List<String[]> resultList = firstPlusSecond.getResult(userIdSkuIdMap, userIdList, "45980");
        dataLoader.write(resultList);

    }

}
